home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Python 1.3.3 / Python 133 SRC / Mac / Modules / ae / aescan.py < prev    next >
Text File  |  1996-04-12  |  3KB  |  107 lines

  1. # Scan AppleEvents.h header file, generate aegen.py and AppleEvents.py files.
  2. # Then run aesupport to generate AEmodule.c.
  3. 0# (Should learn how to tell the compiler to compile it as well.)
  4.  
  5. import addpack
  6. addpack.addpack(':Tools:bgen:bgen')
  7. import sys
  8. import os
  9. import string
  10. import regex
  11. import regsub
  12. import MacOS
  13. from bgenlocations import TOOLBOXDIR
  14.  
  15. from scantools import Scanner
  16.  
  17. def main():
  18.     print "=== Scanning AERegistry.h for defines ==="
  19.     input = "AERegistry.h"
  20.     output = "@dummy-registry.py"
  21.     defsoutput = TOOLBOXDIR + "AERegistry.py"
  22.     scanner = AppleEventsScanner(input, output, defsoutput)
  23.     scanner.scan()
  24.     scanner.close()
  25.     print "=== Scanning AEObjects.h for defines ==="
  26.     # XXXX This isn't correct. We only scan AEObjects.h for defines, but there
  27.     # are some functions in there that are probably useful (the accessor stuff)
  28.     # once we start writing servers in python.
  29.     input = "AEObjects.h"
  30.     output = "@dummy-objects.py"
  31.     defsoutput = TOOLBOXDIR + "AEObjects.py"
  32.     scanner = AppleEventsScanner(input, output, defsoutput)
  33.     scanner.scan()
  34.     scanner.close()
  35.     print "=== Scanning AppleEvents.py ==="
  36.     input = "AppleEvents.h"
  37.     output = "aegen.py"
  38.     defsoutput = TOOLBOXDIR + "AppleEvents.py"
  39.     scanner = AppleEventsScanner(input, output, defsoutput)
  40.     scanner.scan()
  41.     scanner.close()
  42.     print "=== Done Scanning and Generating, now doing 'import aesupport' ==="
  43.     import aesupport
  44.     print "=== Done 'import aesupport'.  It's up to you to compile AEmodule.c ==="
  45.  
  46. class AppleEventsScanner(Scanner):
  47.  
  48.     def destination(self, type, name, arglist):
  49.         classname = "AEFunction"
  50.         listname = "functions"
  51.         if arglist:
  52.             t, n, m = arglist[0]
  53.             if t[-4:] == "_ptr" and m == "InMode" and \
  54.                t[:-4] in ("AEDesc", "AEAddressDesc", "AEDescList",
  55.                      "AERecord", "AppleEvent"):
  56.                 classname = "AEMethod"
  57.                 listname = "aedescmethods"
  58.         return classname, listname
  59.  
  60.     def makeblacklistnames(self):
  61.         return [
  62.             "AEDisposeDesc",
  63. #            "AEGetEventHandler",
  64.             ]
  65.  
  66.     def makeblacklisttypes(self):
  67.         return [
  68.             "ProcPtr",
  69.             "AEArrayType",
  70.             "AECoercionHandlerUPP",
  71.             "UniversalProcPtr",
  72.             ]
  73.  
  74.     def makerepairinstructions(self):
  75.         return [
  76.             ([("Boolean", "isSysHandler", "InMode")],
  77.              [("AlwaysFalse", "*", "*")]),
  78.             
  79.             ([("void_ptr", "*", "InMode"), ("Size", "*", "InMode")],
  80.              [("InBuffer", "*", "*")]),
  81.             
  82.             ([("EventHandlerProcPtr", "*", "InMode"), ("long", "*", "InMode")],
  83.              [("EventHandler", "*", "*")]),
  84.             
  85.             ([("EventHandlerProcPtr", "*", "OutMode"), ("long", "*", "OutMode")],
  86.              [("EventHandler", "*", "*")]),
  87.             
  88.             ([("AEEventHandlerUPP", "*", "InMode"), ("long", "*", "InMode")],
  89.              [("EventHandler", "*", "*")]),
  90.             
  91.             ([("AEEventHandlerUPP", "*", "OutMode"), ("long", "*", "OutMode")],
  92.              [("EventHandler", "*", "*")]),
  93.             
  94.             ([("void", "*", "OutMode"), ("Size", "*", "InMode"),
  95.                                         ("Size", "*", "OutMode")],
  96.              [("VarVarOutBuffer", "*", "InOutMode")]),
  97.              
  98.             ([("AppleEvent", "theAppleEvent", "OutMode")],
  99.              [("AppleEvent_ptr", "*", "InMode")]),
  100.              
  101.             ([("AEDescList", "theAEDescList", "OutMode")],
  102.              [("AEDescList_ptr", "*", "InMode")]),
  103.             ]
  104.  
  105. if __name__ == "__main__":
  106.     main()
  107.